Passed
Push — master ( 44bd30...0dfe52 )
by Evgenii
04:58
created

yii2-floor12-files.js ➔ removeAllFiles   A

Complexity

Conditions 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
1
console.log('Yii2 files model init.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
2
3
4
var currentCroppingImageId;
5
var currentRenamingFileId;
6
var cropper;
7
var removeFileOnCropCancel;
8
var yii2CropperRoute;
9
var yii2UploadRoute;
10
var uploaderSettings = {};
11
12
$(document).on('change', '.yii2-files-upload-field', function () {
13
14
    obj = $(this);
0 ignored issues
show
Bug introduced by
The variable obj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.obj.
Loading history...
15
16
    var formData = new FormData();
17
    formData.append('file', obj[0].files[0]);
18
    formData.append('modelClass', obj.data('modelclass'));
19
    formData.append('attribute', obj.data('attribute'));
20
    formData.append('mode', obj.data('mode'));
21
    formData.append('ratio', obj.data('ratio'));
22
    formData.append('count', 1);
23
    formData.append('_fileFormToken', yii2FileFormToken);
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
24
25
26
    $.ajax({
27
        url: yii2UploadRoute,
0 ignored issues
show
Bug introduced by
The variable yii2UploadRoute seems to be never initialized.
Loading history...
28
        type: 'POST',
29
        data: formData,
30
        processData: false,  // tell jQuery not to process the data
31
        contentType: false,  // tell jQuery not to set contentType
32
        success: function (response) {
33
            id = '#files-widget-block_' + obj.data('block');
0 ignored issues
show
Bug introduced by
The variable id seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.id.
Loading history...
34
            $(response).appendTo(id).find('div.floor12-files-widget-list');
35
        }
36
    });
37
});
38
39
40
function clipboard(text) {
41
    //based on https://stackoverflow.com/a/12693636
42
    document.oncopy = function (event) {
43
        event.clipboardData.setData("Text", text);
44
        event.preventDefault();
45
    };
46
    document.execCommand("Copy");
47
    document.oncopy = undefined;
48
    f12notification.info(text, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
49
}
50
51
function updateProgressCircle(val, btnGroup) {
52
    result = 169.646 * (1 - val / 100);
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
53
    btnGroup.querySelector('svg #progress-circle').setAttribute('stroke-dashoffset', result);
54
    btnGroup.querySelector('.floor12-file-percents').innerHTML = val + '%';
55
    // setAttribute('stroke-dashoffset', result);
56
}
57
58
var observer = new MutationObserver(function (mutations) {
0 ignored issues
show
Bug introduced by
The variable MutationObserver seems to be never declared. If this is a global, consider adding a /** global: MutationObserver */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
59
    percent = mutations[0].target.style.width.replace('%', '');
0 ignored issues
show
Bug introduced by
The variable percent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.percent.
Loading history...
60
    btnGroup = mutations[0].target.parentElement.parentElement;
0 ignored issues
show
Bug introduced by
The variable btnGroup seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.btnGroup.
Loading history...
61
    updateProgressCircle(percent, btnGroup);
62
});
63
64
var lastUploader = null;
65
66
function Yii2FilesUploaderSet(id, className, attribute, scenario) {
67
68
    var mode = 'multi';
69
    var blockName = "#" + id;
70
    var block = $(blockName);
71
    var uploadButton = block.find('button.btn-upload')[0];
72
    var filesList = block.find('.floor12-files-widget-list')[0];
73
    var ratio = 0;
74
75
    var csrf = block.parents('form').find('input[name=' + yii2CsrfParam + ']').val();
0 ignored issues
show
Bug introduced by
The variable yii2CsrfParam seems to be never declared. If this is a global, consider adding a /** global: yii2CsrfParam */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
76
77
    if (block.data('ratio'))
78
        ratio = block.data('ratio');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
79
80
    if (block.hasClass('floor12-files-widget-single-block')) {
81
        mode = 'single';
82
        toggleSingleUploadButton(block);
83
    }
84
85
    uploaderSettings[id] = {
86
        modelClass: className,
87
        attribute: attribute,
88
        scenario: scenario,
89
        mode: mode,
90
        ratio: ratio,
91
        count: block.find('.floor12-files-widget-list .floor12-file-object').length,
92
        _fileFormToken: yii2FileFormToken
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
93
    }
94
95
    uploaderSettings[id][yii2CsrfParam] = csrf
96
    console.log(uploaderSettings[id]);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
97
    var uploader = new ss.SimpleUpload({
0 ignored issues
show
Bug introduced by
The variable ss seems to be never declared. If this is a global, consider adding a /** global: ss */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
98
        button: uploadButton,
99
        url: yii2UploadRoute,
0 ignored issues
show
Bug introduced by
The variable yii2UploadRoute seems to be never initialized.
Loading history...
100
        name: 'file',
101
        dropzone: block,
102
        dragClass: 'floor12-files-widget-block-drug-over',
103
        multiple: true,
104
        multipleSelect: true,
105
        data: uploaderSettings[id],
106
        onSubmit: function (filename, extension, uploadBtn, size) {
0 ignored issues
show
Unused Code introduced by
The parameter uploadBtn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter extension is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter size is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
107
            uploaderSettings[id].count++;
108
            var svg = '\t<svg class="progress-circle" width="60" height="60" viewBox="0 0 60 60">\n' +
109
                '\t\t<circle cx="30" cy="30" r="27" fill="none" stroke="#ccc" stroke-width="5" />\n' +
110
                '\t\t<circle id="progress-circle" cx="30" cy="30" r="27" fill="none" stroke="#666" stroke-width="5" stroke-dasharray="169.646" stroke-dashoffset="169.646" />\n' +
111
                '\t</svg>';
112
113
            var fileId = generateId(filename);
114
            var btnGroup = document.createElement('div');
115
            var fileObject = document.createElement('div');
116
            var bar = document.createElement('div');
117
            var percents = document.createElement('div');
118
            btnGroup.setAttribute('id', fileId);
119
            btnGroup.className = 'btn-group files-btn-group';
120
            fileObject.className = 'floor12-file-object';
121
            percents.className = 'floor12-file-percents';
122
            this.setProgressBar(bar);
123
124
            fileObject.innerHTML = svg;
125
126
            observer.observe(bar, {
127
                attributes: true
128
            });
129
130
            fileObject.appendChild(bar);
131
            fileObject.appendChild(percents);
132
            btnGroup.appendChild(fileObject);
133
134
            if (mode == 'single') {
135
                $(filesList).html('');
136
            }
137
            $(filesList).append(btnGroup);
138
        },
139
        onComplete: function (filename, response) {
140
            if (!response) {
141
                console.log(filename + 'upload failed');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
142
                uploaderSettings[id].count--;
143
                return false;
144
            }
145
            f12notification.info(FileUploadedText, 1);
0 ignored issues
show
Bug introduced by
The variable FileUploadedText seems to be never declared. If this is a global, consider adding a /** global: FileUploadedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
146
            idName = "#" + generateId(filename);
0 ignored issues
show
Bug introduced by
The variable idName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.idName.
Loading history...
147
            $(idName).replaceWith($(response));
148
            if (mode == 'single')
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if mode == "single" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
149
                toggleSingleUploadButton(block);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
150
        },
151
        onError: function (filename, errorType, status, statusText, response, uploadBtn, fileSize) {
0 ignored issues
show
Unused Code introduced by
The parameter fileSize is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter uploadBtn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
152
            console.log(uploaderSettings[id]);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
153
            uploaderSettings[id].count--;
154
            data = {
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
155
                responseText: response,
156
                status: status,
157
                statusText: statusText,
158
            };
159
            processError(data);
160
            idName = "#" + generateId(filename);
0 ignored issues
show
Bug introduced by
The variable idName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.idName.
Loading history...
161
            $(idName).remove();
162
        }
163
164
        //     progressUrl: 'uploadProgress.php', // enables cross-browser progress support (more info below)
165
        //     responseType: 'json',
166
        //    allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
167
        //   maxSize: 1024, // kilobytes
168
        //     hoverClass: 'ui-state-hover',
169
        //     focusClass: 'ui-state-focus',
170
        //     disabledClass: 'ui-state-disabled',
171
    });
172
    lastUploader = uploader;
173
}
174
175
function generateId(filename) {
176
    return 'id-' + filename.replace(/[^0-9a-zA-Z]/g, "");
177
}
178
179
function showUploadButton(event) {
180
    obj = $(event.target);
0 ignored issues
show
Bug introduced by
The variable obj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.obj.
Loading history...
181
    obj.parents('div.floor12-files-widget-single-block').find('button').show();
182
}
183
184
function toggleSingleUploadButton(block) {
185
    if (block.find('div.floor12-single-file-object').length > 0)
186
        block.find('button').hide();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
187
    else
188
        block.find('button').show();
189
}
190
191
function sortableFiles() {
192
    $(".floor12-files-widget-list-multi").sortable({
193
        opacity: 0.5,
194
        revert: 1,
195
        items: "div.files-btn-group",
196
        connectWith: ".floor12-files-widget-list-multi"
197
    });
198
}
199
200
function removeFile(id) {
201
    id = "#yii2-file-object-" + id;
202
    const blockId = $(id).parents('.files-widget-block').attr('id');
203
204
    $(id).parents('div.files-btn-group').fadeOut(200, function () {
205
        $(this).remove();
206
        f12notification.info(FileRemovedText, 1);
0 ignored issues
show
Bug introduced by
The variable FileRemovedText seems to be never declared. If this is a global, consider adding a /** global: FileRemovedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
207
    });
208
209
    uploaderSettings[blockId].count--;
210
    return false;
211
}
212
213
function removeAllFiles(event) {
214
    console.log('removeAllFiles');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
215
    $(event.target).parents('div.floor12-files-widget-list').find('div.files-btn-group').fadeOut(200, function () {
216
        $(this).remove();
217
    });
218
    const blockId = $(event.target).parents('.floor12-files-widget-block').attr('id');
219
    uploaderSettings[blockId].count = 0;
220
    f12notification.info(FilesRemovedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FilesRemovedText seems to be never declared. If this is a global, consider adding a /** global: FilesRemovedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
221
    return false;
222
}
223
224
function initCropperLayout() {
225
    if (yii2CropperRoute.length > 0)
0 ignored issues
show
Bug introduced by
The variable yii2CropperRoute seems to be never initialized.
Loading history...
226
        $.get(yii2CropperRoute, function (response) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
227
            $('body').append(response);
228
229
            $('#yii2-file-title-editor input').on('keyup', function (e) {
230
                if (e.keyCode == 13) {
231
                    saveFileTitle()
232
                }
233
            });
234
        })
235
}
236
237
function initCropper(id, url, ratio, remove) {
238
    $('#cropperModal').modal({keyboard: false, backdrop: 'static'});
239
240
    currentCroppingImageId = id;
241
242
    removeFileOnCropCancel = false;
243
    if (remove)
244
        removeFileOnCropCancel = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
245
246
    currentCropImage = $('<img>').attr('src', url);
0 ignored issues
show
Bug introduced by
The variable currentCropImage seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.currentCropImage.
Loading history...
247
    $('#cropperArea').html("");
248
    $('#cropperArea').append(currentCropImage);
249
250
    autoCrop = false;
0 ignored issues
show
Bug introduced by
The variable autoCrop seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.autoCrop.
Loading history...
251
    aspectRatio = NaN;
0 ignored issues
show
Bug introduced by
The variable aspectRatio seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.aspectRatio.
Loading history...
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name NaN as aspectRatio. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
252
    $('#cropper-btn-cancel').show();
253
254
    console.log(cropperHideCancel);
0 ignored issues
show
Bug introduced by
The variable cropperHideCancel seems to be never declared. If this is a global, consider adding a /** global: cropperHideCancel */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
255
    if (cropperHideCancel == 'true') {
256
        $('#cropper-btn-cancel').hide();
257
    }
258
259
260
    if (ratio) {
261
        autoCrop = true;
262
        aspectRatio = ratio;
263
        $('.cropper-ratio-btn-group').hide();
264
    }
265
266
    setTimeout(function () {
267
        cropper = currentCropImage.cropper({
268
            viewMode: 1,
269
            background: false,
270
            zoomable: false,
271
            autoCrop: autoCrop,
272
            aspectRatio: aspectRatio,
273
        });
274
    }, 1000)
275
}
276
277
function stopCrop(id) {
0 ignored issues
show
Unused Code introduced by
The parameter id is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
278
    $('#cropperModal').modal('hide');
279
    if (removeFileOnCropCancel)
280
        removeFile(currentCroppingImageId);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
281
}
282
283
function cropImage() {
284
    сropBoxData = cropper.cropper('getCropBoxData');
0 ignored issues
show
Bug introduced by
The variable сropBoxData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.сropBoxData.
Loading history...
285
    imageData = cropper.cropper('getImageData');
0 ignored issues
show
Bug introduced by
The variable imageData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.imageData.
Loading history...
286
    canvasData = cropper.cropper('getCanvasData');
0 ignored issues
show
Bug introduced by
The variable canvasData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.canvasData.
Loading history...
287
    ratio = imageData.height / imageData.naturalHeight;
0 ignored issues
show
Bug introduced by
The variable ratio seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.ratio.
Loading history...
288
    cropLeft = (сropBoxData.left - canvasData.left) / ratio;
0 ignored issues
show
Bug introduced by
The variable cropLeft seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropLeft.
Loading history...
289
    cropTop = (сropBoxData.top - canvasData.top) / ratio;
0 ignored issues
show
Bug introduced by
The variable cropTop seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropTop.
Loading history...
290
    cropWidth = сropBoxData.width / ratio;
0 ignored issues
show
Bug introduced by
The variable cropWidth seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropWidth.
Loading history...
291
    cropHeight = сropBoxData.height / ratio;
0 ignored issues
show
Bug introduced by
The variable cropHeight seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropHeight.
Loading history...
292
    rotated = imageData.rotate;
0 ignored issues
show
Bug introduced by
The variable rotated seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.rotated.
Loading history...
293
294
    data = {
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
295
        id: currentCroppingImageId,
296
        width: cropWidth,
297
        height: cropHeight,
298
        top: cropTop,
299
        left: cropLeft,
300
        rotated: rotated,
301
        _fileFormToken: yii2FileFormToken
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
302
    };
303
304
    removeFileOnCropCancel = false;
305
306
    $.ajax({
307
        url: yii2CropRoute,
0 ignored issues
show
Bug introduced by
The variable yii2CropRoute seems to be never declared. If this is a global, consider adding a /** global: yii2CropRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
308
        'method': 'POST',
309
        data: data,
310
        success: function (response) {
311
            id = '#yii2-file-object-' + currentCroppingImageId;
0 ignored issues
show
Bug introduced by
The variable id seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.id.
Loading history...
312
            if ($(id).find('img').length)
313
                $(id).find('img').attr('src', response);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
314
            else {
315
                $(id).css('background-image', 'none');
316
                $(id).css('background-image', 'url(' + response + ')');
317
            }
318
            stopCrop();
319
            f12notification.info(FileSavedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileSavedText seems to be never declared. If this is a global, consider adding a /** global: FileSavedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
320
        },
321
        error: function (response) {
322
            processError(response);
323
        }
324
    })
325
}
326
327
function showRenameFileForm(id, event) {
328
    var blockId = '#yii2-file-object-' + id;
329
    var title = $(blockId).attr('title');
330
    currentRenamingFileId = id;
331
    $('#yii2-file-title-editor').css('top', event.clientY).css('left', event.clientX - 70).fadeIn(100);
332
    $('#yii2-file-title-editor input').val(title).focus();
333
}
334
335
function showAltForm(id, event) {
336
    var blockId = '#yii2-file-object-' + id;
337
    var alt = $(blockId).data('alt');
338
    console.log(alt);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
339
    currentRenamingFileId = id;
340
    $('#yii2-file-alt-editor').css('top', event.clientY).css('left', event.clientX - 70).fadeIn(100);
341
    $('#yii2-file-alt-editor input').val(alt).focus();
342
}
343
344
function hideYii2FileTitleEditor() {
345
    $('#yii2-file-title-editor').fadeOut(100);
346
    currentRenamingFileId = null;
347
}
348
349
function hideYii2FileAltEditor() {
350
    $('#yii2-file-alt-editor').fadeOut(100);
351
    currentRenamingFileId = null;
352
}
353
354
function saveFileTitle() {
355
    $('#yii2-file-title-editor').fadeOut(100);
356
    val = $('#yii2-file-title-editor input').val();
0 ignored issues
show
Bug introduced by
The variable val seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.val.
Loading history...
357
    blockId = '#yii2-file-object-' + currentRenamingFileId;
0 ignored issues
show
Bug introduced by
The variable blockId seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.blockId.
Loading history...
358
    $(blockId).attr('title', val);
359
    $(blockId).attr('data-title', val);
360
361
    $.ajax({
362
            url: yii2RenameRoute,
0 ignored issues
show
Bug introduced by
The variable yii2RenameRoute seems to be never declared. If this is a global, consider adding a /** global: yii2RenameRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
363
            method: 'POST',
364
            data: {id: currentRenamingFileId, title: val, _fileFormToken: yii2FileFormToken},
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
365
            success: function () {
366
                f12notification.info(FileRenamedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileRenamedText seems to be never declared. If this is a global, consider adding a /** global: FileRenamedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
367
            },
368
            error: function (response) {
369
                processError(response);
370
            }
371
        }
372
    );
373
    currentRenamingFileId = null;
374
}
375
376
function saveFileAlt() {
377
    $('#yii2-file-alt-editor').fadeOut(100);
378
    val = $('#yii2-file-alt-editor input').val();
0 ignored issues
show
Bug introduced by
The variable val seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.val.
Loading history...
379
    blockId = '#yii2-file-object-' + currentRenamingFileId;
0 ignored issues
show
Bug introduced by
The variable blockId seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.blockId.
Loading history...
380
    $(blockId).data('alt', val)
381
382
    $.ajax({
383
            url: yii2AltRoute,
0 ignored issues
show
Bug introduced by
The variable yii2AltRoute seems to be never declared. If this is a global, consider adding a /** global: yii2AltRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
384
            method: 'POST',
385
            data: {id: currentRenamingFileId, alt: val, _fileFormToken: yii2FileFormToken},
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
386
            success: function () {
387
                f12notification.info(FileRenamedText, 1);
0 ignored issues
show
Bug introduced by
The variable FileRenamedText seems to be never declared. If this is a global, consider adding a /** global: FileRenamedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
388
            },
389
            error: function (response) {
390
                processError(response);
391
            }
392
        }
393
    );
394
    currentRenamingFileId = null;
395
}
396
397
$(document).ready(function () {
398
    setInterval(function () {
399
        sortableFiles()
400
    }, 2000);
401
402
    sortableFiles();
403
404
    initCropperLayout();
405
406
});
407
408
409